'''
版权: Copyright (c) 2019 red

文件: idmis_app.py
创建日期: Mondy March 18th 2019
作者: linjinkun
说明:
1、工业互联网标识管理系统
'''
from pao_python.pao.app import BaseApp, JsonRpcApp
from pao_python.pao import log
import register.ianalysis_statistics_service as analysis_statistics
import register.industry_product_service as industry_product
import register.handle_analysis_sign_service as analysis_sign
from app.permission import Permission
import pao_python.pao.service.security.security_register as login_service
import register.handle_management_service as handle_management
import register.user_func_register as user_func_register
import register.upload_file as upload_file
import register.stencil_management_service as stencil_management
import register.classify_service as classify
# 工业互联网标识管理系统APP类


class IDMISApp(JsonRpcApp):

    permission_table = Permission()

    def __init__(self, app_name, address, port, web_origins, db_addr, db_port, db_name, inital_password, web_path, upload_file, certificate_path=None, private_path=None):
        JsonRpcApp.__init__(self, app_name, address, port,
                            web_origins, certificate_path, private_path)
        self.db_addr = db_addr
        self.db_port = db_port
        self.db_name = db_name
        self.inital_password = inital_password
        self.web_path = web_path
        self.upload_file = upload_file

    def on_regsiter_services(self, jsonrpc, session):
        # 标识管理系统服务注册
        log('', '标识管理系统运行成功')
        permission_list = self.permission_table.permission_list()
        # 统计服务
        analysis_statistics.register(
            jsonrpc, self.db_addr, self.db_port, self.db_name, session)
        # 行业字典&&产品类型字典
        industry_product.register(
            jsonrpc, self.db_addr, self.db_port, self.db_name)
        # 标识解析服务
        analysis_sign.register(jsonrpc, self.db_addr,
                               self.db_port, self.db_name, session)
        # 登录权限服务
        login_service.register(jsonrpc, self.db_addr, self.db_port,
                               self.db_name, permission_list, self.inital_password, session)
        # 标识管理服务
        handle_management.register(jsonrpc, self.db_addr, self.db_name,
                                   self.db_port, session, self.inital_password, self.web_path, self.upload_file)
        # 用户服务
        user_func_register.register(
            jsonrpc, self.db_addr, self.db_port, self.db_name, self.inital_password, session)
        # 模版管理服务
        stencil_management.register(
            jsonrpc, self.db_addr, self.db_name, self.db_port, session, self.inital_password)
        # 分类服务
        classify.register(
            jsonrpc, self.db_addr, self.db_name, self.db_port, session, self.inital_password)

    # 注册文件上传服务
    def on_regsiter_upload(self, app, jsonrpc):
        upload_file.register(app, self.web_path, self.upload_file,
                             jsonrpc, self.db_addr, self.db_port, self.db_name)
